set memory 200m
* NOTE: You need to set the Stata working directory to the path
* where the data file is located.

set more off

clear
quietly infix              ///
  int     year      1-4    ///
  long    serial    5-9    ///
  float   hhwt      10-16  ///
  byte    reportyr  17-18  ///
  float   perwt     19-26  ///
  byte    age       27-28  ///
  byte    sex       29-29  ///
  int     race      30-32  ///
  byte    marst     33-33  ///
  int     hispan    34-36  ///
  int     educ      37-39  ///
  int     occ       40-42  ///
  int     ind       43-46  ///
  byte    wkswork1  47-48  ///
  byte    wkswork2  49-49  ///
  byte    uhrswork  50-51  ///
  long    incwage   52-57  ///
  byte    vetstat   58-58  ///
  using `"cps_00022.dat"'

replace hhwt     = hhwt     / 100
replace perwt    = perwt    / 100

format hhwt     %7.2f
format perwt    %8.2f

label var year     `"Survey year"'
label var serial   `"Household serial number"'
label var hhwt     `"Household weight"'
label var reportyr `"Reported survey year"'
label var perwt    `"Person weight"'
label var age      `"Age"'
label var sex      `"Sex"'
label var race     `"Race"'
label var marst    `"Marital status"'
label var hispan   `"Hispanic origin"'
label var educ     `"Educational attainment recode"'
label var occ      `"Occupation"'
label var ind      `"Industry"'
label var wkswork1 `"Weeks worked last year"'
label var wkswork2 `"Weeks worked last year, intervalled"'
label var uhrswork `"Usual hours worked per week (last yr)"'
label var incwage  `"Wage and salary income"'
label var vetstat  `"Veteran status"'


drop if sex==2
/*
label define sex_lbl 1 `"Male"'
label define sex_lbl 2 `"Female"', add
label values sex sex_lbl

label define race_lbl 100 `"White"'
label define race_lbl 200 `"Black/Negro"', add
label define race_lbl 300 `"American Indian/Aleut/Eskimo"', add
label define race_lbl 650 `"Asian or Pacific Islander"', add
label define race_lbl 651 `"Asian only"', add
label define race_lbl 652 `"Hawaiian/Pacific Islander only"', add
label define race_lbl 700 `"Other (single) race, n.e.c."', add
label define race_lbl 801 `"White-Black"', add
label define race_lbl 802 `"White-American Indian"', add
label define race_lbl 803 `"White-Asian"', add
label define race_lbl 804 `"White-Hawaiian/Pacific Islander"', add
label define race_lbl 805 `"Black-American Indian"', add
label define race_lbl 806 `"Black-Asian"', add
label define race_lbl 807 `"Black-Hawaiian/Pacific Islander"', add
label define race_lbl 808 `"American Indian-Asian"', add
label define race_lbl 809 `"Asian-Hawaiian/Pacific Islander"', add
label define race_lbl 810 `"White-Black-American Indian"', add
label define race_lbl 811 `"White-Black-Asian"', add
label define race_lbl 812 `"White-American Indian-Asian"', add
label define race_lbl 813 `"White-Asian-Hawaiian/Pacific Islander"', add
label define race_lbl 814 `"White-Black-American Indian-Asian"', add
label define race_lbl 820 `"Two or three races, unspecified"', add
label define race_lbl 830 `"Four or five races, unspecified"', add
label values race race_lbl



label define marst_lbl 1 `"Married, spouse present"'
label define marst_lbl 2 `"Married, spouse absent"', add
label define marst_lbl 3 `"Separated"', add
label define marst_lbl 4 `"Divorced"', add
label define marst_lbl 5 `"Widowed"', add
label define marst_lbl 6 `"Never married/single"', add
label define marst_lbl 9 `"Unknown"', add
label values marst marst_lbl


label define hispan_lbl 000 `"Not Hispanic"'
label define hispan_lbl 100 `"Mexican"', add
label define hispan_lbl 102 `"Mexican American"', add
label define hispan_lbl 103 `"Mexicano/Mexicana"', add
label define hispan_lbl 104 `"Chicano/Chicana"', add
label define hispan_lbl 108 `"Mexican (Mexicano)"', add
label define hispan_lbl 109 `"Mexicano/Chicano"', add
label define hispan_lbl 200 `"Puerto Rican"', add
label define hispan_lbl 300 `"Cuban"', add
label define hispan_lbl 400 `"Other Spanish"', add
label define hispan_lbl 410 `"Central/South American"', add
label define hispan_lbl 901 `"Do not know"', add
label define hispan_lbl 902 `"N/A (and no response 1985-87)"', add
label values hispan hispan_lbl

label define educ_lbl 000 `"NIU or no schooling"'
label define educ_lbl 001 `"NIU"', add
label define educ_lbl 002 `"None or preschool"', add
label define educ_lbl 010 `"Grades 1, 2, 3, or 4"', add
label define educ_lbl 011 `"Grade 1"', add
label define educ_lbl 012 `"Grade 2"', add
label define educ_lbl 013 `"Grade 3"', add
label define educ_lbl 014 `"Grade 4"', add
label define educ_lbl 020 `"Grades 5 or 6"', add
label define educ_lbl 021 `"Grade 5"', add
label define educ_lbl 022 `"Grade 6"', add
label define educ_lbl 030 `"Grades 7 or 8"', add
label define educ_lbl 031 `"Grade 7"', add
label define educ_lbl 032 `"Grade 8"', add
label define educ_lbl 040 `"Grade 9"', add
label define educ_lbl 050 `"Grade 10"', add
label define educ_lbl 060 `"Grade 11"', add
label define educ_lbl 070 `"Grade 12"', add
label define educ_lbl 071 `"12th grade, no diploma"', add
label define educ_lbl 072 `"12th grade, diploma unclear"', add
label define educ_lbl 073 `"High school diploma or equivalent"', add
label define educ_lbl 080 `"1 year of college"', add
label define educ_lbl 081 `"Some college but no degree"', add
label define educ_lbl 090 `"2 years of college"', add
label define educ_lbl 091 `"Associate's degree, occupational/vocational program"', add
label define educ_lbl 092 `"Associate's degree, academic program"', add
label define educ_lbl 100 `"3 years of college"', add
label define educ_lbl 110 `"4 years of college"', add
label define educ_lbl 111 `"Bachelor's degree"', add
label define educ_lbl 112 `"6+ years of college"', add
label define educ_lbl 113 `"Master's degree"', add
label define educ_lbl 114 `"Professional school degree"', add
label define educ_lbl 115 `"Doctorate degree"', add
label define educ_lbl 999 `"Missing/Unknown"', add
label values educ educ_lbl

label define incwage_lbl 999999 `"999999"'
label values incwage incwage_lbl

label define vetstat_lbl 0 `"NIU"'
label define vetstat_lbl 1 `"No service"', add
label define vetstat_lbl 2 `"Yes"', add
label define vetstat_lbl 9 `"Unknown"', add
label values vetstat vetstat_lbl
*/

gen hsgrad=educ==72|educ==73
gen college_grad=educ>=110
keep if hsgrad==1 | college_grad==1

gen black=race==200|race==801|race==804|race==806|race==805|race==810|race==811|race==814
gen white=race==100
gen other_race=1-black-white
gen hispanic=hispan>0
replace white=0 if hispanic==1
replace black=0 if hispanic==1
replace other_race=0 if hispanic==1
gen race4=white+2*black+3*other_race+4*hispanic
# delimit ;

label var race4 "=1 if white, 2=black, 3=other, 4=hispanic'
gen veteran=vetstat==2";

gen marital_status=marst<=2;
replace marital_status=2 if marst==3|marst==4;
replace marital_status=3 if marst==5;
replace marital_status=4 if marst==6;
drop if marst>6;


label var marital_status "=1 married,2=divorce/sep,3=widowed, 4=never married";

gen veteran=vetstat==2;
label var veteran "=1 if veteran";

keep if uhrswork>=30;
keep if incwage>0;
keep if wkswork1>=40;
gen weekly_earn=incwage/wkswork1;

# delimit ;

gen hourly_wage=weekly_earn/uhrswork;
sort year;
egen wage03=pctile(hourly_wage), by(year) p(3);
egen wage99=pctile(hourly_wage), by(year) p(99);
drop if hourly_wage<wage03;
drop if hourly_wage>wage99;
label var weekly_earn "weekly earnings";
label var hourly_wage "hourly wage";

label var college_grad "=1 if college grad, =0 if high school";
keep year age race4 veteran college_grad weekly_earn hourly_wage wkswork1 uhrswork marital_status;
desc;
keep if age<=49;
save march_cps_males, replace;